<?
    $offset = $request->get("offset", "0");
    my @bugs = $EQW->ListBugs($offset);
    my $bug_count = @bugs;
    my $total_bug_count = $EQW->CountBugs();
    print "{";
    print "\"total_bug_count\" : $total_bug_count,";
    print "\"bug_count\" : $bug_count,";
    print "\"bugs\" : ";
    print "[";
    my $i = 0;
    for my $bugkey (@bugs) {
        my $bug = $EQW->GetBugDetails($bugkey);

        my $bug_val = $bug->{bug};
        $bug_val =~ s/\\/\\\\/g;
        $bug_val =~ s/\//\\\//g;
        $bug_val =~ s/\"/\\\"/g;
        $bug_val =~ s/\n/<br>/g;
        $bug_val =~ s/\r/\\r/g;
        $bug_val =~ s/\t/\\t/g;
        $bug_val =~ s/\x08/\\f/g;
        $bug_val =~ s/\x0C/\\b/g;
        $bug_val =~ s/[\x00-\x1F]/\./g;
        $bug_val =~ s/[\x7F-\xFF]/\./g;
        print "{";
        print "\"id\" : \"$bug->{id}\",";
        print "\"name\" : \"$bug->{name}\",";
        print "\"zone\" : \"$bug->{zone}\",";
        print "\"target\" : \"$bug->{target}\",";
        print "\"bug\" : \"$bug_val\",";
        print "\"x\" : \"$bug->{x}\",";
        print "\"y\" : \"$bug->{y}\",";
        print "\"z\" : \"$bug->{z}\"";

        print "}";
        if($i != $bug_count - 1) {
            print ",";
        }
        $i++;
    }
    print "]";
    print "}";
?>